package com.szitrus.smp.scalseal.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * 描述：
 *
 * @author ssl
 * @create 2020/09/21 10:12
 */
@Configuration
public class JdbcTemplateConfig {

    @Bean(name = "datasource")
    @ConfigurationProperties(prefix = "spring.datasource")
    public HikariDataSource datasource() {
        return DataSourceBuilder.create().type(HikariDataSource.class).build();
    }

    @Bean(name = "jdbcTemplate")
    public JdbcTemplate jdbcTemplate(HikariDataSource topcaPersonDataSource) {
        topcaPersonDataSource.setIdleTimeout(60000);
        topcaPersonDataSource.setConnectionTimeout(60000);
        topcaPersonDataSource.setValidationTimeout(3000);
        topcaPersonDataSource.setMaxLifetime(60000);
        topcaPersonDataSource.setConnectionTestQuery("select 1 from dual");
        return new JdbcTemplate(topcaPersonDataSource);
    }
}
